<template>
  <div style="width:300px">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

      <el-form-item label="类别" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>

      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="ruleForm.userId"></el-input>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>


    </el-form>
  </div>
</template>

<script>
  export default {
    name: "updateType",
    data() {
      return {
        ruleForm: {
          tid: '',
          name: '',
          userId: '',
        },
        rules: {
          name: [
            {required: true, message: '请输入类别', trigger: 'blur'}
          ],
          userId: [
            {required: true, message: '请输入用户ID', trigger: 'blur'}
          ]

        }
      };
    }, methods: {
      submitForm(formName) {
        let _this = this;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            console.log(this.ruleForm);
            let para = {
              tid: this.ruleForm.tid,
              name: this.ruleForm.name,
              userId: this.ruleForm.userId
            };
            console.log(para);
            _this.$axios.post("updType", para).then(resp => {
              if (resp.data == 'success') {
                _this.$alert('修改成功！', '消息', {
                  confirmButtonText: '确定',
                  callback: action => {
                    _this.$router.push('/adminType')
                  }
                })
              }
            })
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
    created() {

      this.ruleForm = this.$route.query.data;

    }


  }
</script>

<style scoped>

</style>
